<?php
require_once 'model/Registration.php';

$regs = array();
if ($eventid == "all") {
	$events = Event::getAllEvents();
	$regarr = array();
	foreach ($events as $event) {
		$regs = array_merge($regs, Registration::getAllRegistrations($event));
	}
} else {
	$event = Event::loadEvent((integer) $eventid);
	$regs = Registration::getAllRegistrations($event);
}
?>
<script>
	function showEntries(text) {
		text = text.replace(/<br\/>/gi, "\n");
		alert(text);
	}
</script>
<div id="datacontainer">
<?php 

if ($eventid == "all") {
	echo "<h3>Alle evenementen (".count($regs)." inschrijvingen)</h3><br/>";
} else {
	echo "<h3>".$event->getName()." (".count($regs)." inschrijvingen)</h3><br/>";
}
?>
	<table id="data">
		<thead>
			<tr>
				<th>Code</th>
				<th>Verantwoordelijke</th>
				<th>Prijs</th>
				<th>Betaald</th>
				<th>Personen</th>
			</tr>
		</thead>
		<tbody>
		<?php
		foreach ($regs as $reg) {?>	
			<tr>
				<td><?php echo $reg->getCode();?></td>
				<td><?php echo $reg->getResponsibleName();?></td>
				<td><?php echo "&euro;".$reg->getTotalCost();?></td>
				<td>
				<?php 
					echo "<form name='toggleform_".$reg->getId()."' style='display:inline;' action='".$incpath."togglePayed.php' method='post'>";
					echo "<input type='hidden' name='regid' value='".$reg->getId()."'/>";
					echo "<input type='hidden' name='eventid' value='".$eventid."'/>";
					if ($reg->isPayed()) {
						echo "<a href='javascript:document.toggleform_".$reg->getId().".submit()'>Ja</a>";
					} else {
						echo "<a href='javascript:document.toggleform_".$reg->getId().".submit()'>Nee</a>";
					}
					echo "</form>";
				?>
				</td>
				<?php 
					$text = "";
					foreach ($reg->getEntries() as $ent) {
						$text .= ucfirst($ent->getFirstname())." ".ucfirst($ent->getLastname())."<br/>";
					}
				?>
				<td><a href="javascript:showEntries('<?php echo $text;?>')"><?php echo count($reg->getEntries());?></a></td>
			</tr>
			<?php } ?>
		</tbody>
	</table>
</div>